package com.lywz.biz.service.test.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lywz.biz.common.entity.example.User;
import com.lywz.biz.dao.test.UserDao;
import com.lywz.biz.service.test.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao dao;

	// @SuppressWarnings("unchecked")
	/* (non-Javadoc)
	 * @see com.lywz.biz.service.test.impl.UserService#validate(com.lywz.biz.common.entity.User)
	 */
	public boolean validate(User user) {
		try {
			List<User> list = (List<User>) dao.retrieveUserBy(user.getName());
			
			if (list.isEmpty()) {
				return false;
			} else {
				if (user.getPassword().equals(list.get(0).getPassword())) {
					return true;
				} else {
					return false;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}
	

	@Override
	public void setUserDao(UserDao udi) {
		this.dao = udi;
		
	}
}
